package com.zhangrui.dao;

import com.zhangrui.pojo.User;
import com.zhangrui.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName:UserDaoText
 * Package:com.zhangrui.dao
 * Description:
 *
 * @Date:2021/8/1113:24
 * @Author:zhangrui@qq.com
 */
//这是一个测试类，测试用mybatis框架连接数据库并操作数据库！！！1
public class UserDaoText {
    //这个是测试普通的select语句！！
    public static void main(String[] args) {
        //第一步，获取SqlSession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        //第二部，执行SQL
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> userList = mapper.getUserList();
        for (User user : userList) {
            System.out.println(user);
        }
        //关闭sql
        sqlSession.close();
    }

    @Test
    public void deleteType() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        int deleteData = userMapper.deleteData(new User(8, "张小胖", "777777777"));
        System.out.println("删除一条数据成功！！！");
        sqlSession.commit();
        sqlSession.close();
    }

}
